home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / tc-arm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-05  |  65.7 KB  |  3,116 lines

  1. /* tc-arm.c  All the arm specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org
  4.  
  5.    Copyright (C) 1994 Free Software Foundation, Inc.
  6.  
  7.    This file is part of GAS, the GNU Assembler.
  8.  
  9.    GAS is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2, or (at your option)
  12.    any later version.
  13.  
  14.    GAS is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU General Public License
  20.    along with GAS; see the file COPYING.  If not, write to
  21.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23. #include <ctype.h>
  24. #define  NO_RELOC 0
  25. #include "as.h"
  26.  
  27. /* need TARGET_CPU */
  28. #include "config.h"
  29.  
  30. #include "obstack.h"
  31. #include <string.h>
  32.  
  33. /* This array holds the chars that always start a comment.  If the
  34.    pre-processor is disabled, these aren't very useful */
  35. CONST char comment_chars[] = "@;";
  36.  
  37. /* This array holds the chars that only start a comment at the beginning of
  38.    a line.  If the line seems to have the form '# 123 filename'
  39.    .line and .file directives will appear in the pre-processed output */
  40. /* Note that input_file.c hand checks for '#' at the beginning of the
  41.    first line of the input file.  This is because the compiler outputs
  42.    #NO_APP at the beginning of its output. */
  43. /* Also note that comments like this one will always work. */
  44. CONST char line_comment_chars[] = "#";
  45.  
  46. CONST char line_separator_chars[] = "";
  47.  
  48. /* Chars that can be used to separate mant from exp in floating point nums */
  49. CONST char EXP_CHARS[] = "eE";
  50.  
  51. /* Chars that mean this number is a floating point constant */
  52. /* As in 0f12.456 */
  53. /* or    0d1.2345e12 */
  54.  
  55. CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  56.  
  57. CONST relax_typeS md_relax_table[1];
  58.  
  59. CONST char *md_shortopts = "";
  60. struct option md_longopts[] = {
  61.   {NULL, no_argument, NULL, 0}
  62. };
  63. size_t md_longopts_size = sizeof(md_longopts);
  64.  
  65. int md_reloc_size = 8;        /* Size of relocation record */
  66.  
  67. struct arm_it
  68. {
  69.   CONST char *error;
  70.   unsigned long instruction;
  71.   int suffix;
  72.   struct
  73.     {
  74.       bfd_reloc_code_real_type type;
  75.       expressionS exp;
  76.       int pc_rel;
  77.     } reloc;
  78. };
  79.  
  80. struct arm_it inst;
  81.  
  82. struct asm_shift
  83. {
  84.   CONST char *template;
  85.   unsigned long value;
  86. };
  87.  
  88. static CONST struct asm_shift shift[] =
  89. {
  90.   {NULL, 0},
  91.   {"asl", 0},
  92.   {"lsl", 0},
  93.   {"lsr", 0x00000020},
  94.   {"asr", 0x00000040},
  95.   {"ror", 0x00000060},
  96.   {"rrx", 0x00000060}
  97. };
  98.  
  99. #define NO_SHIFT_RESTRICT 1
  100. #define SHIFT_RESTRICT      0
  101.  
  102. #define NUM_FLOAT_VALS 8
  103.  
  104. CONST char *fp_const[] = 
  105. {
  106.   "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
  107. };
  108.  
  109. /* Number of littlenums required to hold an extended precision number */
  110. #define MAX_LITTLENUMS 6
  111.  
  112. LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
  113.  
  114. #define FAIL    (-1)
  115. #define SUCCESS (0)
  116.  
  117. #define FLAG_S    0
  118. #define FLAG_P    1
  119. #define FLAG_B    2
  120. #define FLAG_T    3
  121. #define FLAG_ED    4
  122. #define FLAG_FD    5
  123. #define FLAG_EA    6
  124. #define FLAG_FA    7
  125. #define FLAG_IB    8
  126. #define FLAG_IA    9
  127. #define FLAG_DB    10
  128. #define FLAG_DA    11
  129. #define FLAG_L    12
  130.  
  131. #define SUFF_S 1
  132. #define SUFF_D 2
  133. #define SUFF_E 3
  134. #define SUFF_P 4
  135.  
  136. struct asm_cond
  137. {
  138.   CONST char *template;
  139.   unsigned long value;
  140. };
  141.  
  142. /* This is to save a hash look-up in the common case */
  143. #define COND_ALWAYS 0xe0000000
  144.  
  145. static CONST struct asm_cond conds[] = 
  146. {
  147.   {NULL, 0},
  148.   {"eq", 0x00000000},
  149.   {"ne", 0x10000000},
  150.   {"cs", 0x20000000}, {"hs", 0x20000000},
  151.   {"cc", 0x30000000}, {"ul", 0x30000000},
  152.   {"mi", 0x40000000},
  153.   {"pl", 0x50000000},
  154.   {"vs", 0x60000000},
  155.   {"vc", 0x70000000},
  156.   {"hi", 0x80000000},
  157.   {"ls", 0x90000000},
  158.   {"ge", 0xa0000000},
  159.   {"lt", 0xb0000000},
  160.   {"gt", 0xc0000000},
  161.   {"le", 0xd0000000},
  162.   {"al", 0xe0000000},
  163.   {"nv", 0xf0000000}
  164. };
  165.  
  166.  
  167. #define LONGEST_FLAG 2
  168.     
  169. struct asm_flg
  170. {
  171.   CONST char *template;        /* Basic flag string */
  172.   unsigned long more_flags;    /* Flags that may follow this (bit offset) */
  173. };
  174.  
  175. static CONST struct asm_flg flags[] = 
  176. {
  177.   {NULL, 0},
  178.   {"s", 0},
  179.   {"p", 0},
  180.   {"b", 0x10},
  181.   {"t", 0},
  182.   {"ed", 0},
  183.   {"fd", 0},
  184.   {"ea", 0},
  185.   {"fa", 0},
  186.   {"ib", 0},
  187.   {"ia", 0},
  188.   {"db", 0},
  189.   {"da", 0},
  190.   {"l", 0},
  191.   {"m", 0},
  192.   {"z", 0},
  193.   {"e", 0}
  194. };
  195.  
  196. static void do_mul PARAMS ((char *operands, unsigned long flags));
  197. static void do_mla PARAMS ((char *operands, unsigned long flags));
  198. static void do_arit PARAMS ((char *operands, unsigned long flags));
  199. static void do_cmp PARAMS ((char *operands, unsigned long flags));
  200. static void do_mov PARAMS ((char *operands, unsigned long flags));
  201. static void do_ldst PARAMS ((char *operands, unsigned long flags));
  202. static void do_ldmstm PARAMS ((char *operands, unsigned long flags));
  203. static void do_swi PARAMS ((char *operands, unsigned long flags));
  204. static void do_swap PARAMS ((char *operands, unsigned long flags));
  205. static void do_branch PARAMS ((char *operands, unsigned long flags));
  206. static void do_cdp PARAMS ((char *operands, unsigned long flags));
  207. static void do_lstc PARAMS ((char *operands, unsigned long flags));
  208. static void do_co_reg PARAMS ((char *operands, unsigned long flags));
  209. static void do_fp_ctrl PARAMS ((char *operands, unsigned long flags));
  210. static void do_fp_ldst PARAMS ((char *operands, unsigned long flags));
  211. static void do_fp_dyadic PARAMS ((char *operands, unsigned long flags));
  212. static void do_fp_monadic PARAMS ((char *operands, unsigned long flags));
  213. static void do_fp_cmp PARAMS ((char *operands, unsigned long flags));
  214. static void do_fp_from_reg PARAMS ((char *operands, unsigned long flags));
  215. static void do_fp_to_reg PARAMS ((char *operands, unsigned long flags));
  216.  
  217. static void fix_new_arm PARAMS ((fragS *frag, int where, short int size, 
  218.                  expressionS *exp, int pc_rel, int reloc));
  219. static int arm_reg_parse PARAMS ((char **ccp));
  220.  
  221.  
  222. /* All instructions take 4 bytes in the object file */
  223.  
  224. #define INSN_SIZE    4
  225.  
  226. /* LONGEST_INST is the longest basic instruction name without conditions or 
  227.  * flags.  I think there is a four-letter one for floating point (there is!)
  228.  */
  229.  
  230. #define LONGEST_INST 4
  231.  
  232. struct asm_opcode 
  233. {
  234.     CONST char *template;    /* Basic string to match */
  235.     unsigned long value;    /* Basic instruction code */
  236.     CONST char *comp_suffix;    /* Compulsory suffix that must follow conds */
  237.     unsigned long flags[16];    /* Bits to toggle if flag 'n' set */
  238.     void (*parms)();        /* Function to call to parse args */
  239. };
  240.  
  241. #define TRANS_BIT    (0x00200000)
  242.  
  243. static CONST struct asm_opcode insns[] = 
  244. {
  245.   {NULL, 0, 0,
  246.       {0, 0, 0, 0 ,0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0},
  247.       NULL},
  248.   {"mul", 0x00000090, 0,
  249.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  250.       do_mul},
  251.   {"mla", 0x00200090, 0,
  252.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  253.       do_mla},
  254.   {"and", 0x00000000, 0,
  255.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  256.       do_arit},
  257.   {"eor", 0x00200000, 0,
  258.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  259.       do_arit},
  260.   {"sub", 0x00400000, 0,
  261.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  262.       do_arit},
  263.   {"rsb", 0x00600000, 0,
  264.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  265.       do_arit},
  266.   {"add", 0x00800000, 0,
  267.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  268.       do_arit},
  269.   {"adc", 0x00a00000, 0,
  270.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  271.       do_arit},
  272.   {"sbc", 0x00c00000, 0,
  273.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  274.       do_arit},
  275.   {"rsc", 0x00e00000, 0,
  276.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  277.       do_arit},
  278.   {"orr", 0x01800000, 0,
  279.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  280.       do_arit},
  281.   {"bic", 0x01c00000, 0,
  282.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  283.       do_arit},
  284.   {"tst", 0x01000000, 0,
  285.       {0x00100000, 0x0010f000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  286.       do_cmp},
  287.   {"teq", 0x01200000, 0,
  288.       {0x00100000, 0x0010f000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  289.       do_cmp},
  290.   {"cmp", 0x01400000, 0,
  291.       {0x00100000, 0x0010f000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  292.       do_cmp},
  293.   {"cmn", 0x01600000, 0,
  294.       {0x00100000, 0x0010f000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  295.       do_cmp},
  296.   {"mov", 0x01a00000, 0,
  297.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  298.       do_mov},
  299.   {"mvn", 0x01e00000, 0,
  300.       {0x00100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  301.       do_mov},
  302.   {"str", 0x04000000, 0,
  303.       {0, 0, 0x00400000, TRANS_BIT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  304.       do_ldst},
  305.   {"ldr", 0x04100000, 0,
  306.       {0, 0, 0x00400000, TRANS_BIT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  307.       do_ldst},
  308.   {"stm", 0x08000000, 0,
  309.       {0, 0, 0, 0, 0x08000000, 0x01000000, 0x00800000, 0x01800000,
  310.        0x01800000, 0x00800000, 0x01000000, 0x08000000, 0, 0, 0},
  311.       do_ldmstm},
  312.   {"ldm", 0x08100000, 0,
  313.       {0, 0, 0, 0, 0x01800000, 0x00800000, 0x01000000, 0x08000000,
  314.        0x01800000, 0x00800000, 0x01000000, 0x08000000, 0, 0, 0},
  315.       do_ldmstm},
  316.   {"swi", 0x0f000000, 0,
  317.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  318.       do_swi},
  319.   {"swp", 0x01000090, 0,
  320.       {0, 0, 0x00400000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  321.       do_swap},
  322.   {"bl",  0x0b000000, 0,
  323.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  324.       do_branch},
  325.   {"b",   0x0a000000, 0,
  326.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  327.       do_branch},
  328. /* Generic copressor instructions */
  329.   {"cdp",  0x0e000000, 0,
  330.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  331.       do_cdp},
  332.   {"ldc", 0x0c100000, 0,
  333.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00400000, 0, 0},
  334.       do_lstc},
  335.   {"stc", 0x0c000000, 0,
  336.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00400000, 0, 0},
  337.       do_lstc},
  338.   {"mcr", 0x0e000010, 0,
  339.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  340.       do_co_reg},
  341.   {"mrc", 0x0e100010, 0,
  342.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  343.       do_co_reg},
  344. /* Floating point instructions should go here */
  345.   {"wfs", 0x0e200110, 0,
  346.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  347.       do_fp_ctrl},
  348.   {"rfs", 0x0e300110, 0,
  349.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  350.       do_fp_ctrl},
  351.   {"wfc", 0x0e400110, 0,
  352.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  353.       do_fp_ctrl},
  354.   {"rfc", 0x0e500110, 0,
  355.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  356.       do_fp_ctrl},
  357.   {"ldf", 0x0c100100, "sdep",
  358.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  359.       do_fp_ldst},
  360.   {"stf", 0x0c000100, "sdep",
  361.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  362.       do_fp_ldst},
  363.   {"mvf", 0x0e008100, "sde",
  364.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  365.       do_fp_monadic},
  366.   {"mnf", 0x0e108100, "sde",
  367.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  368.       do_fp_monadic},
  369.   {"abs", 0x0e208100, "sde",
  370.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  371.       do_fp_monadic},
  372.   {"rnd", 0x0e308100, "sde",
  373.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  374.       do_fp_monadic},
  375.   {"sqt", 0x0e408100, "sde",
  376.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  377.       do_fp_monadic},
  378.   {"log", 0x0e508100, "sde",
  379.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  380.       do_fp_monadic},
  381.   {"lgn", 0x0e608100, "sde",
  382.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  383.       do_fp_monadic},
  384.   {"exp", 0x0e708100, "sde",
  385.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  386.       do_fp_monadic},
  387.   {"sin", 0x0e808100, "sde",
  388.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  389.       do_fp_monadic},
  390.   {"cos", 0x0e908100, "sde",
  391.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  392.       do_fp_monadic},
  393.   {"tan", 0x0ea08100, "sde",
  394.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  395.       do_fp_monadic},
  396.   {"asn", 0x0eb08100, "sde",
  397.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  398.       do_fp_monadic},
  399.   {"acs", 0x0ec08100, "sde",
  400.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  401.       do_fp_monadic},
  402.   {"atn", 0x0ed08100, "sde",
  403.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  404.       do_fp_monadic},
  405.   {"urd", 0x0ee08100, "sde",
  406.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  407.       do_fp_monadic},
  408.   {"nrm", 0x0ef08100, "sde",
  409.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  410.       do_fp_monadic},
  411.   {"adf", 0x0e000100, "sde",
  412.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  413.       do_fp_dyadic},
  414.   {"suf", 0x0e200100, "sde",
  415.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  416.       do_fp_dyadic},
  417.   {"rsf", 0x0e300100, "sde",
  418.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  419.       do_fp_dyadic},
  420.   {"muf", 0x0e100100, "sde",
  421.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  422.       do_fp_dyadic},
  423.   {"dvf", 0x0e400100, "sde",
  424.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  425.       do_fp_dyadic},
  426.   {"rdf", 0x0e500100, "sde",
  427.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  428.       do_fp_dyadic},
  429.   {"pow", 0x0e600100, "sde",
  430.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  431.       do_fp_dyadic},
  432.   {"rpw", 0x0e700100, "sde",
  433.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  434.       do_fp_dyadic},
  435.   {"rmf", 0x0e800100, "sde",
  436.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  437.       do_fp_dyadic},
  438.   {"fml", 0x0e900100, "sde",
  439.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  440.       do_fp_dyadic},
  441.   {"fdv", 0x0ea00100, "sde",
  442.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  443.       do_fp_dyadic},
  444.   {"frd", 0x0eb00100, "sde",
  445.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  446.       do_fp_dyadic},
  447.   {"pol", 0x0ec00100, "sde",
  448.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  449.       do_fp_dyadic},
  450.   {"cmf", 0x0e90f110, 0,
  451.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00400000},
  452.       do_fp_cmp},
  453.   {"cnf", 0x0eb0f110, 0,
  454.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00400000},
  455.       do_fp_cmp},
  456.   /* The FPA10 data sheet suggests that the 'E' of cmfe/cnfe should not
  457.      be an optional suffix, but part of the instruction.  To be compatible,
  458.      we accept either.  */
  459.   {"cmfe", 0x0ed0f110, 0,
  460.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  461.       do_fp_cmp},
  462.   {"cnfe", 0x0ef0f110, 0,
  463.       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  464.       do_fp_cmp},
  465.   {"flt", 0x0e000110, "sde",
  466.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  467.       do_fp_from_reg},
  468.   {"fix", 0x0e100110, 0,
  469.       {0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x60},
  470.       do_fp_to_reg}
  471. };
  472.  
  473. /* defines for various bits that we will want to toggle */
  474.  
  475. #define INST_IMMEDIATE    0x02000000
  476. #define OFFSET_REG    0x02000000
  477. #define SHIFT_BY_REG    0x00000010
  478. #define PRE_INDEX    0x01000000
  479. #define INDEX_UP    0x00800000
  480. #define WRITE_BACK    0x00200000
  481. #define MULTI_SET_PSR    0x00400000
  482.  
  483. struct reg_entry
  484. {
  485.   CONST char *name;
  486.   int number;
  487. };
  488.  
  489. #define int_register(reg) ((reg) >= 0 && (reg) <= 15)
  490. #define cp_register(reg) ((reg) >= 32 && (reg) <= 47)
  491. #define fp_register(reg) ((reg) >= 16 && (reg) <= 23)
  492.  
  493. #define REG_PC    15
  494.  
  495. /* These are the standard names;  Users can add aliases with .req */
  496. static CONST struct reg_entry reg_table[] =
  497. {
  498.   {"r0", 0},    {"r1", 1},    {"r2", 2},    {"r3", 3},
  499.   {"r4", 4},    {"r5", 5},    {"r6", 6},    {"r7", 7},
  500.   {"r8", 8},    {"r9", 9},    {"r10", 10},  {"r11", 11},
  501.   {"r12", 12},  {"r13", 13},  {"r14", 14},  {"r15", REG_PC},
  502.   {"f0", 16},   {"f1", 17},   {"f2", 18},   {"f3", 19},
  503.   {"f4", 20},   {"f5", 21},   {"f6", 22},   {"f7", 23},
  504.   {"c0", 32},   {"c1", 33},   {"c2", 34},   {"c3", 35},
  505.   {"c4", 36},   {"c5", 37},   {"c6", 38},   {"c7", 39},
  506.   {"c8", 40},   {"c9", 41},   {"c10", 42},  {"c11", 43},
  507.   {"c12", 44},  {"c13", 45},  {"c14", 46},  {"c15", 47},
  508.   {"cr0", 32},  {"cr1", 33},  {"cr2", 34},  {"cr3", 35},
  509.   {"cr4", 36},  {"cr5", 37},  {"cr6", 38},  {"cr7", 39},
  510.   {"cr8", 40},  {"cr9", 41},  {"cr10", 42}, {"cr11", 43},
  511.   {"cr12", 44}, {"cr13", 45}, {"cr14", 46}, {"cr15", 47},
  512.   {NULL, 0}
  513. };
  514.  
  515. static CONST char *bad_args = "Bad arguments to instruction";
  516. static CONST char *bad_pc = "r15 not allowed here";
  517.  
  518. static struct hash_control *arm_ops_hsh = NULL;
  519. static struct hash_control *arm_cond_hsh = NULL;
  520. static struct hash_control *arm_flg_hsh = NULL;
  521. static struct hash_control *arm_shift_hsh = NULL;
  522. static struct hash_control *arm_reg_hsh = NULL;
  523.  
  524. /* This table describes all the machine specific pseudo-ops the assembler
  525.    has to support.  The fields are:
  526.    pseudo-op name without dot
  527.    function to call to execute this pseudo-op
  528.    Integer arg to pass to the function
  529.    */
  530.  
  531. static void s_req PARAMS ((int));
  532. static void s_bss PARAMS ((int));
  533. static void s_align PARAMS ((int));
  534. static void s_even PARAMS ((int));
  535.  
  536. static int my_get_expression PARAMS ((expressionS *, char **));
  537.  
  538. CONST pseudo_typeS md_pseudo_table[] =
  539. {
  540.   {"req", s_req, 0},    /* Never called becasue '.req' does not start line */
  541.   {"bss", s_bss, 0},
  542.   {"align", s_align, 0},
  543.   {"even", s_even, 0},
  544.   {"word", cons, 4},
  545.   {0, 0, 0}
  546. };
  547.  
  548. /* Check that an immediate is valid, and if so, convert it to the right format
  549.  */
  550.  
  551. /* OH, for a rotate instruction in C! */
  552.  
  553. static int
  554. validate_immediate (val)
  555.      int val;
  556. {
  557.   unsigned int a = (unsigned int) val;
  558.   int i;
  559.   
  560.   /* Do the easy (and most common ones) quickly */
  561.   for (i = 0; i <= 24; i += 2)
  562.     {
  563.       if ((a & (0xff << i)) == a)
  564.     return (int) (((32 - i) & 0x1e) << 7) | ((a >> i) & 0xff);
  565.     }
  566.  
  567.   /* Now do the harder ones */
  568.   for (; i < 32; i += 2)
  569.     {
  570.       if ((a & ((0xff << i) | (0xff >> (32 - i)))) == a)
  571.     {
  572.       a = ((a >> i) & 0xff) | ((a << (32 - i)) & 0xff);
  573.       return (int) a | (((32 - i) >> 1) << 8);
  574.     }
  575.     }
  576.   return -1;
  577. }
  578.  
  579. static int
  580. validate_offset_imm (val)
  581.      int val;
  582. {
  583.   if (val < -4095 || val > 4095)
  584.     as_bad ("bad immediate value for offset (%d)", val);
  585.   return val;
  586. }
  587.  
  588.     
  589. static void
  590. s_req (a)
  591.      int a;
  592. {
  593.   as_bad ("Invalid syntax for .req directive.");
  594. }
  595.  
  596. static void
  597. s_bss (ignore)
  598.      int ignore;
  599. {
  600.   /* We don't support putting frags in the BSS segment, we fake it by
  601.      marking in_bss, then looking at s_skip for clues?.. */
  602.   subseg_set (bss_section, 0);
  603.   demand_empty_rest_of_line ();
  604. }
  605.  
  606. static void
  607. s_even (ignore)
  608.      int ignore;
  609. {
  610.   if (!need_pass_2)        /* Never make frag if expect extra pass. */
  611.     frag_align (1, 0);
  612.   record_alignment (now_seg, 1);
  613.   demand_empty_rest_of_line ();
  614. }
  615.  
  616. static void
  617. s_align (unused)    /* Same as s_align_ptwo but align 0 => align 2 */
  618.      int unused;
  619. {
  620.   register int temp;
  621.   register long temp_fill;
  622.   long max_alignment = 15;
  623.  
  624.   temp = get_absolute_expression ();
  625.   if (temp > max_alignment)
  626.     as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  627.   else if (temp < 0)
  628.     {
  629.       as_bad ("Alignment negative. 0 assumed.");
  630.       temp = 0;
  631.     }
  632.  
  633.   if (*input_line_pointer == ',')
  634.     {
  635.       input_line_pointer++;
  636.       temp_fill = get_absolute_expression ();
  637.     }
  638.   else
  639.     temp_fill = 0;
  640.  
  641.   if (!temp)
  642.     temp = 2;
  643.  
  644.   /* Only make a frag if we HAVE to. . . */
  645.   if (temp && !need_pass_2)
  646.     frag_align (temp, (int) temp_fill);
  647.  
  648.   record_alignment (now_seg, temp);
  649.  
  650.   demand_empty_rest_of_line ();
  651. }
  652.  
  653. static void
  654. end_of_line (str)
  655.      char *str;
  656. {
  657.   while (*str == ' ')
  658.     str++;
  659.  
  660.   if (*str != '\0')
  661.     inst.error = "Garbage following instruction";
  662. }
  663.  
  664. static int
  665. skip_past_comma (str)
  666.      char **str;
  667. {
  668.   char *p = *str, c;
  669.   int comma = 0;
  670.     
  671.   while ((c = *p) == ' ' || c == ',')
  672.     {
  673.       p++;
  674.       if (c == ',' && comma++)
  675.     return FAIL;
  676.     }
  677.  
  678.   if (c == '\0')
  679.     return FAIL;
  680.  
  681.   *str = p;
  682.   return comma ? SUCCESS : FAIL;
  683. }
  684.  
  685. /* A standard register must be given at this point.  Shift is the place to
  686.    put it in the instruction. */
  687.  
  688. static int
  689. reg_required_here (str, shift)
  690.      char **str;
  691.      int shift;
  692. {
  693.   int reg;
  694.   char *start = *str;
  695.  
  696.   if ((reg = arm_reg_parse (str)) != FAIL && int_register (reg))
  697.     {
  698.       inst.instruction |= reg << shift;
  699.       return reg;
  700.     }
  701.  
  702.   /* In the few cases where we might be able to accept something else
  703.      this error can be overridden */
  704.   inst.error = "Register expected";
  705.  
  706.   /* Restore the start point, we may have got a reg of the wrong class.  */
  707.   *str = start;
  708.   return FAIL;
  709. }
  710.  
  711. static int co_proc_number (str)
  712.      char **str;
  713. {
  714.   int processor, pchar;
  715.  
  716.   while (**str == ' ')
  717.     (*str)++;
  718.  
  719.   /* The data sheet seems to imply that just a number on its own is valid
  720.      here, but the RISC iX assembler seems to accept a prefix 'p'.  We will
  721.      accept either.  */
  722.   if (**str == 'p' || **str == 'P')
  723.     (*str)++;
  724.  
  725.   pchar = *(*str)++;
  726.   if (pchar >= '0' && pchar <= '9')
  727.     {
  728.       processor = pchar - '0';
  729.       if (**str >= '0' && **str <= '9')
  730.     {
  731.       processor = processor * 10 + *(*str)++ - '0';
  732.       if (processor > 15)
  733.         {
  734.           inst.error = "Illegal co-processor number";
  735.           return FAIL;
  736.         }
  737.     }
  738.     }
  739.   else
  740.     {
  741.       inst.error = "Bad or missing co-processor number";
  742.       return FAIL;
  743.     }
  744.  
  745.   inst.instruction |= processor << 8;
  746.   return SUCCESS;
  747. }
  748.  
  749. static int
  750. cp_opc_expr (str, where, length)
  751.      char **str;
  752.      int where;
  753.      int length;
  754. {
  755.   expressionS expr;
  756.  
  757.   while (**str == ' ')
  758.     (*str)++;
  759.  
  760.   memset (&expr, '\0', sizeof (expr));
  761.  
  762.   if (my_get_expression (&expr, str))
  763.     return FAIL;
  764.   if (expr.X_op != O_constant)
  765.     {
  766.       inst.error = "bad or missing expression";
  767.       return FAIL;
  768.     }
  769.  
  770.   if ((expr.X_add_number & ((1 << length) - 1)) != expr.X_add_number)
  771.     {
  772.       inst.error = "immediate co-processor expression too large";
  773.       return FAIL;
  774.     }
  775.  
  776.   inst.instruction |= expr.X_add_number << where;
  777.   return SUCCESS;
  778. }
  779.  
  780. static int
  781. cp_reg_required_here (str, where)
  782.      char **str;
  783.      int where;
  784. {
  785.   int reg;
  786.   char *start = *str;
  787.  
  788.   if ((reg = arm_reg_parse (str)) != FAIL && cp_register (reg))
  789.     {
  790.       reg &= 15;
  791.       inst.instruction |= reg << where;
  792.       return reg;
  793.     }
  794.  
  795.   /* In the few cases where we might be able to accept something else
  796.      this error can be overridden */
  797.   inst.error = "Co-processor register expected";
  798.  
  799.   /* Restore the start point */
  800.   *str = start;
  801.   return FAIL;
  802. }
  803.  
  804. static int
  805. fp_reg_required_here (str, where)
  806.      char **str;
  807.      int where;
  808. {
  809.   int reg;
  810.   char *start = *str;
  811.  
  812.   if ((reg = arm_reg_parse (str)) != FAIL && fp_register (reg))
  813.     {
  814.       reg &= 7;
  815.       inst.instruction |= reg << where;
  816.       return reg;
  817.     }
  818.  
  819.   /* In the few cases where we might be able to accept something else
  820.      this error can be overridden */
  821.   inst.error = "Floating point register expected";
  822.  
  823.   /* Restore the start point */
  824.   *str = start;
  825.   return FAIL;
  826. }
  827.  
  828. static int
  829. cp_address_offset (str)
  830.      char **str;
  831. {
  832.   int offset;
  833.  
  834.   while (**str == ' ')
  835.     (*str)++;
  836.  
  837.   if (**str != '#')
  838.     {
  839.       inst.error = "immediate expression expected";
  840.       return FAIL;
  841.     }
  842.  
  843.   (*str)++;
  844.   if (my_get_expression (&inst.reloc.exp, str))
  845.     return FAIL;
  846.   if (inst.reloc.exp.X_op == O_constant)
  847.     {
  848.       offset = inst.reloc.exp.X_add_number;
  849.       if (offset & 3)
  850.     {
  851.       inst.error = "co-processor address must be word aligned";
  852.       return FAIL;
  853.     }
  854.  
  855.       if (offset > 1023 || offset < -1023)
  856.     {
  857.       inst.error = "offset too large";
  858.       return FAIL;
  859.     }
  860.  
  861.       if (offset >= 0)
  862.     inst.instruction |= INDEX_UP;
  863.       else
  864.     offset = -offset;
  865.  
  866.       inst.instruction |= offset >> 2;
  867.     }
  868.   else
  869.     inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
  870.  
  871.   return SUCCESS;
  872. }
  873.  
  874. static int
  875. cp_address_required_here (str)
  876.      char **str;
  877. {
  878.   char *p = *str;
  879.   int pre_inc = 0;
  880.   int write_back = 0;
  881.  
  882.   if (*p == '[')
  883.     {
  884.       int reg;
  885.  
  886.       p++;
  887.       while (*p == ' ')
  888.     p++;
  889.  
  890.       if ((reg = reg_required_here (&p, 16)) == FAIL)
  891.     {
  892.       inst.error = "Register required";
  893.       return FAIL;
  894.     }
  895.  
  896.       while (*p == ' ')
  897.     p++;
  898.  
  899.       if (*p == ']')
  900.     {
  901.       p++;
  902.       if (skip_past_comma (&p) == SUCCESS)
  903.         {
  904.           /* [Rn], #expr */
  905.           write_back = WRITE_BACK;
  906.           if (reg == REG_PC)
  907.         {
  908.           inst.error = "pc may not be used in post-increment";
  909.           return FAIL;
  910.         }
  911.  
  912.           if (cp_address_offset (&p) == FAIL)
  913.         return FAIL;
  914.         }
  915.     }
  916.       else
  917.     {
  918.       /* '['Rn, #expr']'[!] */
  919.  
  920.       if (skip_past_comma (&p) == FAIL)
  921.         {
  922.           inst.error = "pre-indexed expression expected";
  923.           return FAIL;
  924.         }
  925.  
  926.       pre_inc = PRE_INDEX;
  927.       if (cp_address_offset (&p) == FAIL)
  928.         return FAIL;
  929.  
  930.       while (*p == ' ')
  931.         p++;
  932.  
  933.       if (*p++ != ']')
  934.         {
  935.           inst.error = "missing ]";
  936.           return FAIL;
  937.         }
  938.  
  939.       while (*p == ' ')
  940.         p++;
  941.  
  942.       if (*p == '!')
  943.         {
  944.           if (reg == REG_PC)
  945.         {
  946.           inst.error = "pc may not be used with write-back";
  947.           return FAIL;
  948.         }
  949.  
  950.           p++;
  951.           write_back = WRITE_BACK;
  952.         }
  953.     }
  954.     }
  955.   else
  956.     {
  957.       if (my_get_expression (&inst.reloc.exp, &p))
  958.     return FAIL;
  959.  
  960.       inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
  961.       inst.reloc.exp.X_add_number -= 8;  /* PC rel adjust */
  962.       inst.reloc.pc_rel = 1;
  963.       inst.instruction |= (REG_PC << 16);
  964.     }
  965.  
  966.   inst.instruction |= write_back | pre_inc;
  967.   *str = p;
  968.   return SUCCESS;
  969. }
  970.  
  971. static void
  972. do_mul (str, flags)
  973.      char *str;
  974.      unsigned long flags;
  975. {
  976.   int rd, rm;
  977.   
  978.   /* only one format "rd, rm, rs" */
  979.   while (*str == ' ')
  980.     str++;
  981.  
  982.   if ((rd = reg_required_here (&str, 16)) == FAIL)
  983.     {
  984.       inst.error = bad_args;
  985.       return;
  986.     }
  987.  
  988.   if (rd == REG_PC)
  989.     {
  990.       inst.error = bad_pc;
  991.       return;
  992.     }
  993.  
  994.   if (skip_past_comma (&str) == FAIL
  995.       || (rm = reg_required_here (&str, 0)) == FAIL)
  996.     {
  997.       inst.error = bad_args;
  998.       return;
  999.     }
  1000.  
  1001.   if (rm == REG_PC)
  1002.     {
  1003.       inst.error = bad_pc;
  1004.       return;
  1005.     }
  1006.  
  1007.   if (rm == rd)
  1008.     as_tsktsk ("Warning: rd and rm should be different in mul");
  1009.  
  1010.   if (skip_past_comma (&str) == FAIL
  1011.       || (rm = reg_required_here (&str, 8)) == FAIL)
  1012.     {
  1013.       inst.error = bad_args;
  1014.       return;
  1015.     }
  1016.  
  1017.   if (rm == REG_PC)
  1018.     {
  1019.       inst.error = bad_pc;
  1020.       return;
  1021.     }
  1022.  
  1023.   inst.instruction |= flags;
  1024.   end_of_line (str);
  1025.   return;
  1026. }
  1027.  
  1028. static void
  1029. do_mla (str, flags)
  1030.      char *str;
  1031.      unsigned long flags;
  1032. {
  1033.   int rd, rm;
  1034.  
  1035.   /* only one format "rd, rm, rs, rn" */
  1036.   while (*str == ' ')
  1037.     str++;
  1038.  
  1039.   if ((rd = reg_required_here (&str, 16)) == FAIL)
  1040.     {
  1041.       inst.error = bad_args;
  1042.       return;
  1043.     }
  1044.  
  1045.   if (rd == REG_PC)
  1046.     {
  1047.       inst.error = bad_pc;
  1048.       return;
  1049.     }
  1050.  
  1051.   if (skip_past_comma (&str) == FAIL
  1052.       || (rm = reg_required_here (&str, 0)) == FAIL)
  1053.     {
  1054.       inst.error = bad_args;
  1055.       return;
  1056.     }
  1057.  
  1058.   if (rm == REG_PC)
  1059.     {
  1060.       inst.error = bad_pc;
  1061.       return;
  1062.     }
  1063.  
  1064.   if (rm == rd)
  1065.     as_tsktsk ("Warning: rd and rm should be different in mla");
  1066.  
  1067.   if (skip_past_comma (&str) == FAIL
  1068.       || (rd = reg_required_here (&str, 8)) == FAIL
  1069.       || skip_past_comma (&str) == FAIL
  1070.       || (rm = reg_required_here (&str, 12)) == FAIL)
  1071.     {
  1072.       inst.error = bad_args;
  1073.       return;
  1074.     }
  1075.  
  1076.   if (rd == REG_PC || rm == REG_PC)
  1077.     {
  1078.       inst.error = bad_pc;
  1079.       return;
  1080.     }
  1081.  
  1082.   inst.instruction |= flags;
  1083.   end_of_line (str);
  1084.   return;
  1085. }
  1086.  
  1087. /* Returns the index into fp_values of a floating point number, or -1 if
  1088.    not in the table.  */
  1089. static int
  1090. my_get_float_expression (str)
  1091.      char **str;
  1092. {
  1093.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1094.   char *save_in;
  1095.   expressionS exp;
  1096.   int i, j;
  1097.  
  1098.   memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
  1099.   /* Look for a raw floating point number */
  1100.   if ((save_in = atof_ieee (*str, 'x', words)) != NULL
  1101.       && (is_end_of_line [(int)(*save_in)] || *save_in == '\0'))
  1102.     {
  1103.       for (i = 0; i < NUM_FLOAT_VALS; i++)
  1104.     {
  1105.       for (j = 0; j < MAX_LITTLENUMS; j++)
  1106.         {
  1107.           if (words[j] != fp_values[i][j])
  1108.         break;
  1109.         }
  1110.  
  1111.       if (j == MAX_LITTLENUMS)
  1112.         {
  1113.           *str = save_in;
  1114.           return i;
  1115.         }
  1116.     }
  1117.     }
  1118.  
  1119.   /* Try and parse a more complex expression, this will probably fail
  1120.      unless the code uses a floating point prefix (eg "0f") */
  1121.   save_in = input_line_pointer;
  1122.   input_line_pointer = *str;
  1123.   if (expression (&exp) == absolute_section
  1124.       && exp.X_op == O_big
  1125.       && exp.X_add_number < 0)
  1126.     {
  1127.       if (gen_to_words (words, 6, (long)15) == 0)
  1128.     {
  1129.       for (i = 0; i < NUM_FLOAT_VALS; i++)
  1130.         {
  1131.           for (j = 0; j < MAX_LITTLENUMS; j++)
  1132.         {
  1133.           if (words[j] != fp_values[i][j])
  1134.             break;
  1135.         }
  1136.  
  1137.           if (j == MAX_LITTLENUMS)
  1138.         {
  1139.           *str = input_line_pointer;
  1140.           input_line_pointer = save_in;
  1141.           return i;
  1142.         }
  1143.         }
  1144.     }
  1145.     }
  1146.  
  1147.   *str = input_line_pointer;
  1148.   input_line_pointer = save_in;
  1149.   return -1;
  1150. }
  1151.  
  1152. /* Return true if anything in the expression is a bignum */
  1153. static int
  1154. walk_no_bignums (sp)
  1155.      symbolS *sp;
  1156. {
  1157.   if (sp->sy_value.X_op == O_big)
  1158.     return 1;
  1159.  
  1160.   if (sp->sy_value.X_add_symbol)
  1161.     {
  1162.       return (walk_no_bignums (sp->sy_value.X_add_symbol)
  1163.           || (sp->sy_value.X_op_symbol
  1164.           && walk_no_bignums (sp->sy_value.X_op_symbol)));
  1165.     }
  1166.  
  1167.   return 0;
  1168. }
  1169.   
  1170. static int
  1171. my_get_expression (ep, str)
  1172.      expressionS *ep;
  1173.      char **str;
  1174. {
  1175.   char *save_in;
  1176.   segT seg;
  1177.   
  1178.   save_in = input_line_pointer;
  1179.   input_line_pointer = *str;
  1180.   seg = expression (ep);
  1181.   if (seg != absolute_section
  1182.       && seg != text_section
  1183.       && seg != data_section
  1184.       && seg != bss_section
  1185.       && seg != undefined_section)
  1186.     {
  1187.       inst.error = "bad_segment";
  1188.       *str = input_line_pointer;
  1189.       input_line_pointer = save_in;
  1190.       return 1;
  1191.     }
  1192.  
  1193.   if (ep->X_op == O_big
  1194.       || (ep->X_add_symbol
  1195.       && (walk_no_bignums (ep->X_add_symbol)
  1196.           || (ep->X_op_symbol
  1197.           && walk_no_bignums (ep->X_op_symbol)))))
  1198.     {
  1199.       inst.error = "Invalid constant";
  1200.       *str = input_line_pointer;
  1201.       input_line_pointer = save_in;
  1202.       return 1;
  1203.     }
  1204.  
  1205.   *str = input_line_pointer;
  1206.   input_line_pointer = save_in;
  1207.   return 0;
  1208. }
  1209.  
  1210. /* unrestrict should be one if <shift> <register> is permitted for this
  1211.    instruction */
  1212.  
  1213. static int
  1214. decode_shift (str, unrestrict)
  1215. char **str;
  1216. int unrestrict;
  1217. {
  1218.   struct asm_shift *shft;
  1219.   char *p;
  1220.   char c;
  1221.     
  1222.   while (**str == ' ')
  1223.     (*str)++;
  1224.     
  1225.   for (p = *str; isalpha (*p); p++)
  1226.     ;
  1227.  
  1228.   if (p == *str)
  1229.     {
  1230.       inst.error = "Shift expression expected";
  1231.       return FAIL;
  1232.     }
  1233.  
  1234.   c = *p;
  1235.   *p = '\0';
  1236.   shft = (struct asm_shift *) hash_find (arm_shift_hsh, *str);
  1237.   *p = c;
  1238.   if (shft)
  1239.     {
  1240.       if (!strcmp (*str, "rrx"))
  1241.     {
  1242.       *str = p;
  1243.       inst.instruction |= shft->value;
  1244.       return SUCCESS;
  1245.     }
  1246.  
  1247.       while (*p == ' ')
  1248.     p++;
  1249.  
  1250.       if (unrestrict && reg_required_here (&p, 8) != FAIL)
  1251.     {
  1252.       inst.instruction |= shft->value | SHIFT_BY_REG;
  1253.       *str = p;
  1254.       return SUCCESS;
  1255.     }
  1256.       else if (*p == '#')
  1257.     {
  1258.       inst.error = NULL;
  1259.       p++;
  1260.       if (my_get_expression (&inst.reloc.exp, &p))
  1261.         return FAIL;
  1262.  
  1263.       /* Validate some simple #expressions */
  1264.       if (!inst.reloc.exp.X_add_symbol)
  1265.         {
  1266.           int num = inst.reloc.exp.X_add_number;
  1267.           if (num < 0 || num > 32
  1268.           || (num == 32 
  1269.               && (shft->value == 0 || shft->value == 0x60)))
  1270.         {
  1271.           inst.error = "Invalid immediate shift";
  1272.           return FAIL;
  1273.         }
  1274.  
  1275.           /* Shifts of zero should be converted to lsl (which is zero)*/
  1276.           if (num == 0)
  1277.         {
  1278.           *str = p;
  1279.           return SUCCESS;
  1280.         }
  1281.  
  1282.           /* Shifts of 32 are encoded as 0, for those shifts that
  1283.          support it.  */
  1284.           if (num == 32)
  1285.         num = 0;
  1286.  
  1287.           inst.instruction |= (num << 7) | shft->value;
  1288.           *str = p;
  1289.           return SUCCESS;
  1290.         }
  1291.  
  1292.       inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
  1293.       inst.reloc.pc_rel = 0;
  1294.       inst.instruction |= shft->value;
  1295.       *str = p;
  1296.       return SUCCESS;
  1297.     }
  1298.       else
  1299.     {
  1300.       inst.error = unrestrict ? "shift requires register or #expression"
  1301.         : "shift requires #expression";
  1302.       *str = p;
  1303.       return FAIL;
  1304.     }
  1305.     }
  1306.  
  1307.   inst.error = "Shift expression expected";
  1308.   return FAIL;
  1309. }
  1310.  
  1311. static int
  1312. data_op2 (str)
  1313.      char **str;
  1314. {
  1315.   while (**str == ' ')
  1316.     (*str)++;
  1317.     
  1318.   if (reg_required_here (str, 0) != FAIL)
  1319.     {
  1320.       if (skip_past_comma (str) == SUCCESS)
  1321.     {
  1322.       /* Shift operation on register */
  1323.       return decode_shift (str, NO_SHIFT_RESTRICT);
  1324.     }
  1325.       return SUCCESS;
  1326.     }
  1327.   else
  1328.     {
  1329.       /* Immediate expression */
  1330.       if (*((*str)++) == '#')
  1331.     {
  1332.       inst.error = NULL;
  1333.       if (my_get_expression (&inst.reloc.exp, str))
  1334.         return FAIL;
  1335.  
  1336.       if (inst.reloc.exp.X_add_symbol)
  1337.         {
  1338.           inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
  1339.           inst.reloc.pc_rel = 0;
  1340.         }
  1341.       else
  1342.         {
  1343.           int value = validate_immediate (inst.reloc.exp.X_add_number);
  1344.  
  1345.           if (value == -1)
  1346.         {
  1347.           inst.error = "Invalid constant";
  1348.           return FAIL;
  1349.         }
  1350.  
  1351.           inst.instruction |= value;
  1352.         }
  1353.  
  1354.       inst.instruction |= INST_IMMEDIATE;
  1355.       return SUCCESS;
  1356.     }
  1357.  
  1358.       inst.error = "Register or shift expression expected";
  1359.       return FAIL;
  1360.     }
  1361. }
  1362.  
  1363. static int
  1364. fp_op2 (str, flags)
  1365.      char **str;
  1366.      unsigned long flags;
  1367. {
  1368.   while (**str == ' ')
  1369.     (*str)++;
  1370.  
  1371.   if (fp_reg_required_here (str, 0) != FAIL)
  1372.     return SUCCESS;
  1373.   else
  1374.     {
  1375.       /* Immediate expression */
  1376.       if (*((*str)++) == '#')
  1377.     {
  1378.       int i;
  1379.  
  1380.       inst.error = NULL;
  1381.       while (**str == ' ')
  1382.         (*str)++;
  1383.  
  1384.       /* First try and match exact strings, this is to guarantee that
  1385.          some formats will work even for cross assembly */
  1386.  
  1387.       for (i = 0; fp_const[i]; i++)
  1388.         {
  1389.           if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
  1390.         {
  1391.           char *start = *str;
  1392.  
  1393.           *str += strlen (fp_const[i]);
  1394.           if (is_end_of_line [(int)**str] || **str == '\0')
  1395.             {
  1396.               inst.instruction |= i + 8;
  1397.               return SUCCESS;
  1398.             }
  1399.           *str = start;
  1400.         }
  1401.         }
  1402.  
  1403.       /* Just because we didn't get a match doesn't mean that the
  1404.          constant isn't valid, just that it is in a format that we
  1405.          don't automatically recognize.  Try parsing it with
  1406.          the standard expression routines.  */
  1407.       if ((i = my_get_float_expression (str)) >= 0)
  1408.         {
  1409.           inst.instruction |= i + 8;
  1410.           return SUCCESS;
  1411.         }
  1412.  
  1413.       inst.error = "Invalid floating point immediate expression";
  1414.       return FAIL;
  1415.     }
  1416.       inst.error = "Floating point register or immediate expression expected";
  1417.       return FAIL;
  1418.     }
  1419. }
  1420.  
  1421. static void
  1422. do_arit (str, flags)
  1423.      char *str;
  1424.      unsigned long flags;
  1425. {
  1426.   while (*str == ' ')
  1427.     str++;
  1428.  
  1429.   if (reg_required_here (&str, 12) == FAIL)
  1430.     {
  1431.       if (!inst.error)
  1432.     inst.error = bad_args;
  1433.       return;
  1434.     }
  1435.  
  1436.   if (skip_past_comma (&str) == FAIL
  1437.       || reg_required_here (&str, 16) == FAIL)
  1438.     {
  1439.       if (!inst.error)
  1440.     inst.error = bad_args;
  1441.       return;
  1442.     }
  1443.  
  1444.   if (skip_past_comma (&str) == FAIL
  1445.       || data_op2 (&str) == FAIL)
  1446.     {
  1447.       if (!inst.error)
  1448.     inst.error = bad_args;
  1449.       return;
  1450.     }
  1451.  
  1452.   inst.instruction |= flags;
  1453.   end_of_line (str);
  1454.   return;
  1455. }
  1456.  
  1457. static void
  1458. do_cmp (str, flags)
  1459.      char *str;
  1460.      unsigned long flags;
  1461. {
  1462.   while (*str == ' ')
  1463.     str++;
  1464.  
  1465.   if (reg_required_here (&str, 16) == FAIL)
  1466.     {
  1467.       if (!inst.error)
  1468.     inst.error = bad_args;
  1469.       return;
  1470.     }
  1471.  
  1472.   if (skip_past_comma (&str) == FAIL
  1473.       || data_op2 (&str) == FAIL)
  1474.     {
  1475.       if (!inst.error)
  1476.     inst.error = bad_args;
  1477.       return;
  1478.     }
  1479.  
  1480.   inst.instruction |= flags;
  1481.   if ((flags & 0x0000f000) == 0)
  1482.     inst.instruction |= 0x00100000;
  1483.   end_of_line (str);
  1484.   return;
  1485. }
  1486.  
  1487. static void
  1488. do_mov (str, flags)
  1489.      char *str;
  1490.      unsigned long flags;
  1491. {
  1492.   while (*str == ' ')
  1493.     str++;
  1494.  
  1495.   if (reg_required_here (&str, 12) == FAIL)
  1496.     {
  1497.       if (!inst.error)
  1498.     inst.error = bad_args;
  1499.       return;
  1500.     }
  1501.  
  1502.   if (skip_past_comma (&str) == FAIL
  1503.       || data_op2 (&str) == FAIL)
  1504.     {
  1505.       if (!inst.error)
  1506.     inst.error = bad_args;
  1507.       return;
  1508.     }
  1509.  
  1510.   inst.instruction |= flags;
  1511.   end_of_line (str);
  1512.   return;
  1513. }
  1514.  
  1515. static int
  1516. ldst_extend (str)
  1517.      char **str;
  1518. {
  1519.   int add = INDEX_UP;
  1520.  
  1521.   switch (**str)
  1522.     {
  1523.     case '#':
  1524.       (*str)++;
  1525.       if (my_get_expression (&inst.reloc.exp, str))
  1526.     return FAIL;
  1527.  
  1528.       if (inst.reloc.exp.X_op == O_constant)
  1529.     {
  1530.       int value = inst.reloc.exp.X_add_number;
  1531.  
  1532.       if (value < -4095 || value > 4095)
  1533.         {
  1534.           inst.error = "address offset too large";
  1535.           return FAIL;
  1536.         }
  1537.  
  1538.       if (value < 0)
  1539.         {
  1540.           value = -value;
  1541.           add = 0;
  1542.         }
  1543.  
  1544.       inst.instruction |= add | value;
  1545.     }
  1546.       else
  1547.     {
  1548.       inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
  1549.       inst.reloc.pc_rel = 0;
  1550.     }
  1551.       return SUCCESS;
  1552.  
  1553.     case '-':
  1554.       add = 0;    /* and fall through */
  1555.     case '+':
  1556.       (*str)++;    /* and fall through */
  1557.     default:
  1558.       if (reg_required_here (str, 0) == FAIL)
  1559.     {
  1560.       inst.error = "Register expected";
  1561.       return FAIL;
  1562.     }
  1563.       inst.instruction |= add | OFFSET_REG;
  1564.       if (skip_past_comma (str) == SUCCESS)
  1565.     return decode_shift (str, SHIFT_RESTRICT);
  1566.       return SUCCESS;
  1567.     }
  1568. }
  1569.  
  1570. static void
  1571. do_ldst (str, flags)
  1572.      char *str;
  1573.      unsigned long flags;
  1574. {
  1575.   int pre_inc = 0;
  1576.   int conflict_reg;
  1577.  
  1578.   while (*str == ' ')
  1579.     str++;
  1580.     
  1581.   if ((conflict_reg = reg_required_here (&str, 12)) == FAIL)
  1582.     {
  1583.       if (!inst.error)
  1584.     inst.error = bad_args;
  1585.       return;
  1586.     }
  1587.  
  1588.   if (skip_past_comma (&str) == FAIL)
  1589.     {
  1590.       inst.error = "Address expected";
  1591.       return;
  1592.     }
  1593.  
  1594.   if (*str == '[')
  1595.     {
  1596.       int reg;
  1597.  
  1598.       str++;
  1599.       while (*str == ' ')
  1600.     str++;
  1601.  
  1602.       if ((reg = reg_required_here (&str, 16)) == FAIL)
  1603.     {
  1604.       inst.error = "Register required";
  1605.       return;
  1606.     }
  1607.  
  1608.       conflict_reg = (((conflict_reg == reg)
  1609.                && (inst.instruction & 0x00100000))
  1610.               ? 1 : 0);
  1611.  
  1612.       while (*str == ' ')
  1613.     str++;
  1614.  
  1615.       if (*str == ']')
  1616.     {
  1617.       str++;
  1618.       if (skip_past_comma (&str) == SUCCESS)
  1619.         {
  1620.           /* [Rn],... (post inc) */
  1621.           if (ldst_extend (&str) == FAIL)
  1622.         return;
  1623.           if (conflict_reg)
  1624.         as_warn ("destination register same as write-back base\n");
  1625.         }
  1626.       else
  1627.         {
  1628.           /* [Rn] */
  1629.           flags |= INDEX_UP;
  1630.         }
  1631.     }
  1632.       else
  1633.     {
  1634.       /* [Rn,...] */
  1635.       if (skip_past_comma (&str) == FAIL)
  1636.         {
  1637.           inst.error = "pre-indexed expression expected";
  1638.           return;
  1639.         }
  1640.  
  1641.       pre_inc = 1;
  1642.       if (ldst_extend (&str) == FAIL)
  1643.         return;
  1644.  
  1645.       while (*str == ' ')
  1646.         str++;
  1647.  
  1648.       if (*str++ != ']')
  1649.         {
  1650.           inst.error = "missing ]";
  1651.           return;
  1652.         }
  1653.  
  1654.       while (*str == ' ')
  1655.         str++;
  1656.  
  1657.       if (*str == '!')
  1658.         {
  1659.           if (conflict_reg)
  1660.         as_warn ("destination register same as write-back base\n");
  1661.           str++;
  1662.           inst.instruction |= WRITE_BACK;
  1663.         }
  1664.     }
  1665.     }
  1666.   else
  1667.     {
  1668.       if (my_get_expression (&inst.reloc.exp, &str))
  1669.     return;
  1670.  
  1671.       inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
  1672.       inst.reloc.exp.X_add_number -= 8;  /* PC rel adjust */
  1673.       inst.reloc.pc_rel = 1;
  1674.       inst.instruction |= (REG_PC << 16);
  1675.       pre_inc = 1;
  1676.     }
  1677.     
  1678.   if (pre_inc && (flags & TRANS_BIT))
  1679.     inst.error = "Pre-increment instruction with translate";
  1680.  
  1681.   inst.instruction |= flags | (pre_inc ? PRE_INDEX : 0);
  1682.   end_of_line (str);
  1683.   return;
  1684. }
  1685.  
  1686. static void
  1687. do_ldmstm (str, flags)
  1688.      char *str;
  1689.      unsigned long flags;
  1690. {
  1691.   int base_reg;
  1692.  
  1693.   while (*str == ' ')
  1694.     str++;
  1695.  
  1696.   if ((base_reg = reg_required_here (&str, 16)) == FAIL)
  1697.     {
  1698.       if (!inst.error)
  1699.     inst.error = bad_args;
  1700.       return;
  1701.     }
  1702.  
  1703.   if (base_reg == REG_PC)
  1704.     {
  1705.       inst.error = "r15 not allowed as base register";
  1706.       return;
  1707.     }
  1708.  
  1709.   while (*str == ' ')
  1710.     str++;
  1711.   if (*str == '!')
  1712.     {
  1713.       flags |= WRITE_BACK;
  1714.       str++;
  1715.     }
  1716.  
  1717.   if (skip_past_comma (&str) == FAIL)
  1718.     {
  1719.       inst.error = bad_args;
  1720.       return;
  1721.     }
  1722.  
  1723.   /* We come back here if we get ranges concatenated by '+' or '|' */
  1724.  another_range:
  1725.   if (*str == '{')
  1726.     {
  1727.       int in_range = 0;
  1728.       int cur_reg = -1;
  1729.       
  1730.       str++;
  1731.       do
  1732.     {
  1733.       int reg;
  1734.         
  1735.       while (*str == ' ')
  1736.         str++;
  1737.  
  1738.       if ((reg = arm_reg_parse (&str)) == FAIL || !int_register (reg))
  1739.         {
  1740.           inst.error = "Register expected";
  1741.           return;
  1742.         }
  1743.  
  1744.       if (in_range)
  1745.         {
  1746.           int i;
  1747.           
  1748.           if (reg <= cur_reg)
  1749.         {
  1750.           inst.error = "Bad range in register list";
  1751.           return;
  1752.         }
  1753.  
  1754.           for (i = cur_reg + 1; i < reg; i++)
  1755.         {
  1756.           if (flags & (1 << i))
  1757.             as_tsktsk 
  1758.               ("Warning: Duplicated register (r%d) in register list",
  1759.                i);
  1760.           else
  1761.             flags |= 1 << i;
  1762.         }
  1763.           in_range = 0;
  1764.         }
  1765.  
  1766.       if (flags & (1 << reg))
  1767.         as_tsktsk ("Warning: Duplicated register (r%d) in register list",
  1768.                reg);
  1769.       else if (reg <= cur_reg)
  1770.         as_tsktsk ("Warning: Register range not in ascending order");
  1771.  
  1772.       flags |= 1 << reg;
  1773.       cur_reg = reg;
  1774.     } while (skip_past_comma (&str) != FAIL
  1775.          || (in_range = 1, *str++ == '-'));
  1776.       str--;
  1777.       while (*str == ' ')
  1778.     str++;
  1779.  
  1780.       if (*str++ != '}')
  1781.     {
  1782.       inst.error = "Missing `}'";
  1783.       return;
  1784.     }
  1785.     }
  1786.   else
  1787.     {
  1788.       expressionS expr;
  1789.  
  1790.       if (my_get_expression (&expr, &str))
  1791.     return;
  1792.  
  1793.       if (expr.X_op == O_constant)
  1794.     {
  1795.       if (expr.X_add_number 
  1796.           != (expr.X_add_number & 0x0000ffff))
  1797.         {
  1798.           inst.error = "invalid register mask";
  1799.           return;
  1800.         }
  1801.       if ((flags & expr.X_add_number) != 0)
  1802.         {
  1803.           int regno = flags & expr.X_add_number;
  1804.  
  1805.           regno &= -regno;
  1806.           regno = (1 << regno) - 1;
  1807.           as_tsktsk ("Warning: Duplicated register (r%d) in register list",
  1808.              regno);
  1809.         }
  1810.       flags |= expr.X_add_number;
  1811.     }
  1812.       else
  1813.     {
  1814.       if (inst.reloc.type != 0)
  1815.         {
  1816.           inst.error = "expression too complex";
  1817.           return;
  1818.         }
  1819.  
  1820.       memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
  1821.       inst.reloc.type = BFD_RELOC_ARM_MULTI;
  1822.       inst.reloc.pc_rel = 0;
  1823.     }
  1824.     }
  1825.  
  1826.   while (*str == ' ')
  1827.     str++;
  1828.  
  1829.   if (*str == '|' || *str == '+')
  1830.     {
  1831.       str++;
  1832.       goto another_range;
  1833.     }
  1834.  
  1835.   if (*str == '^')
  1836.     {
  1837.       str++;
  1838.       flags |= MULTI_SET_PSR;
  1839.     }
  1840.   inst.instruction |= flags;
  1841.   end_of_line (str);
  1842.   return;
  1843. }
  1844.  
  1845. static void
  1846. do_swi (str, flags)
  1847.      char *str;
  1848.      unsigned long flags;
  1849. {
  1850.   if (my_get_expression (&inst.reloc.exp, &str))
  1851.     return;
  1852.  
  1853.   inst.reloc.type = BFD_RELOC_ARM_SWI;
  1854.   inst.reloc.pc_rel = 0;
  1855.   inst.instruction |= flags;
  1856.   end_of_line (str);
  1857.   return;
  1858. }
  1859.  
  1860. static void
  1861. do_swap (str, flags)
  1862.      char *str;
  1863.      unsigned long flags;
  1864. {
  1865.   int reg;
  1866.   
  1867.   while (*str == ' ')
  1868.     str++;
  1869.  
  1870.   if ((reg = reg_required_here (&str, 12)) == FAIL)
  1871.     return;
  1872.  
  1873.   if (reg == REG_PC)
  1874.     {
  1875.       inst.error = bad_pc;
  1876.       return;
  1877.     }
  1878.  
  1879.   if (skip_past_comma (&str) == FAIL
  1880.       || (reg = reg_required_here (&str, 0)) == FAIL)
  1881.     {
  1882.       if (!inst.error)
  1883.     inst.error = bad_args;
  1884.       return;
  1885.     }
  1886.  
  1887.   if (reg == REG_PC)
  1888.     {
  1889.       inst.error = bad_pc;
  1890.       return;
  1891.     }
  1892.  
  1893.   if (skip_past_comma (&str) == FAIL
  1894.       || *str++ != '[')
  1895.     {
  1896.       inst.error = bad_args;
  1897.       return;
  1898.     }
  1899.  
  1900.   while (*str == ' ')
  1901.     str++;
  1902.  
  1903.   if ((reg = reg_required_here (&str, 16)) == FAIL)
  1904.     return;
  1905.  
  1906.   if (reg == REG_PC)
  1907.     {
  1908.       inst.error = bad_pc;
  1909.       return;
  1910.     }
  1911.  
  1912.   while (*str == ' ')
  1913.     str++;
  1914.  
  1915.   if (*str++ != ']')
  1916.     {
  1917.       inst.error = "missing ]";
  1918.       return;
  1919.     }
  1920.  
  1921.   inst.instruction |= flags;
  1922.   end_of_line (str);
  1923.   return;
  1924. }
  1925.  
  1926. static void
  1927. do_branch (str, flags)
  1928.      char *str;
  1929.      unsigned long flags;
  1930. {
  1931.   if (my_get_expression (&inst.reloc.exp, &str))
  1932.     return;
  1933.   inst.reloc.type = BFD_RELOC_ARM_PCREL_BRANCH;
  1934.   inst.reloc.pc_rel = 1;
  1935.   inst.instruction |= flags | 0x00fffffe;    /* PC-rel adjust */
  1936.   end_of_line (str);
  1937.   return;
  1938. }
  1939.  
  1940. static void
  1941. do_cdp (str, flags)
  1942.      char *str;
  1943.      unsigned long flags;
  1944. {
  1945.   /* Co-processor data operation.
  1946.      Format: CDP{cond} CP#,<expr>,CRd,CRn,CRm{,<expr>}  */
  1947.   while (*str == ' ')
  1948.     str++;
  1949.  
  1950.   if (co_proc_number (&str) == FAIL)
  1951.     {
  1952.       if (!inst.error)
  1953.     inst.error = bad_args;
  1954.       return;
  1955.     }
  1956.  
  1957.   if (skip_past_comma (&str) == FAIL
  1958.       || cp_opc_expr (&str, 20,4) == FAIL)
  1959.     {
  1960.       if (!inst.error)
  1961.     inst.error = bad_args;
  1962.       return;
  1963.     }
  1964.  
  1965.   if (skip_past_comma (&str) == FAIL
  1966.       || cp_reg_required_here (&str, 12) == FAIL)
  1967.     {
  1968.       if (!inst.error)
  1969.     inst.error = bad_args;
  1970.       return;
  1971.     }
  1972.  
  1973.   if (skip_past_comma (&str) == FAIL
  1974.       || cp_reg_required_here (&str, 16) == FAIL)
  1975.     {
  1976.       if (!inst.error)
  1977.     inst.error = bad_args;
  1978.       return;
  1979.     }
  1980.  
  1981.   if (skip_past_comma (&str) == FAIL
  1982.       || cp_reg_required_here (&str, 0) == FAIL)
  1983.     {
  1984.       if (!inst.error)
  1985.     inst.error = bad_args;
  1986.       return;
  1987.     }
  1988.  
  1989.   if (skip_past_comma (&str) == SUCCESS)
  1990.     {
  1991.       if (cp_opc_expr (&str, 5, 3) == FAIL)
  1992.     {
  1993.       if (!inst.error)
  1994.         inst.error = bad_args;
  1995.       return;
  1996.     }
  1997.     }
  1998.  
  1999.   end_of_line (str);
  2000.   return;
  2001. }
  2002.  
  2003. static void
  2004. do_lstc (str, flags)
  2005.      char *str;
  2006.      unsigned long flags;
  2007. {
  2008.   /* Co-processor register load/store.
  2009.      Format: <LDC|STC{cond}[L] CP#,CRd,<address>  */
  2010.  
  2011.   while (*str == ' ')
  2012.     str++;
  2013.  
  2014.   if (co_proc_number (&str) == FAIL)
  2015.     {
  2016.       if (!inst.error)
  2017.     inst.error = bad_args;
  2018.       return;
  2019.     }
  2020.  
  2021.   if (skip_past_comma (&str) == FAIL
  2022.       || cp_reg_required_here (&str, 12) == FAIL)
  2023.     {
  2024.       if (!inst.error)
  2025.     inst.error = bad_args;
  2026.       return;
  2027.     }
  2028.  
  2029.   if (skip_past_comma (&str) == FAIL
  2030.       || cp_address_required_here (&str) == FAIL)
  2031.     {
  2032.       if (! inst.error)
  2033.     inst.error = bad_args;
  2034.       return;
  2035.     }
  2036.  
  2037.   inst.instruction |= flags;
  2038.   end_of_line (str);
  2039.   return;
  2040. }
  2041.  
  2042. static void
  2043. do_co_reg (str, flags)
  2044.      char *str;
  2045.      unsigned long flags;
  2046. {
  2047.   /* Co-processor register transfer.
  2048.      Format: <MCR|MRC>{cond} CP#,<expr1>,Rd,CRn,CRm{,<expr2>}  */
  2049.  
  2050.   while (*str == ' ')
  2051.     str++;
  2052.  
  2053.   if (co_proc_number (&str) == FAIL)
  2054.     {
  2055.       if (!inst.error)
  2056.     inst.error = bad_args;
  2057.       return;
  2058.     }
  2059.  
  2060.   if (skip_past_comma (&str) == FAIL
  2061.       || cp_opc_expr (&str, 21, 3) == FAIL)
  2062.     {
  2063.       if (!inst.error)
  2064.     inst.error = bad_args;
  2065.       return;
  2066.     }
  2067.  
  2068.   if (skip_past_comma (&str) == FAIL
  2069.       || reg_required_here (&str, 12) == FAIL)
  2070.     {
  2071.       if (!inst.error)
  2072.     inst.error = bad_args;
  2073.       return;
  2074.     }
  2075.  
  2076.   if (skip_past_comma (&str) == FAIL
  2077.       || cp_reg_required_here (&str, 16) == FAIL)
  2078.     {
  2079.       if (!inst.error)
  2080.     inst.error = bad_args;
  2081.       return;
  2082.     }
  2083.  
  2084.   if (skip_past_comma (&str) == FAIL
  2085.       || cp_reg_required_here (&str, 0) == FAIL)
  2086.     {
  2087.       if (!inst.error)
  2088.     inst.error = bad_args;
  2089.       return;
  2090.     }
  2091.  
  2092.   if (skip_past_comma (&str) == SUCCESS)
  2093.     {
  2094.       if (cp_opc_expr (&str, 5, 3) == FAIL)
  2095.     {
  2096.       if (!inst.error)
  2097.         inst.error = bad_args;
  2098.       return;
  2099.     }
  2100.     }
  2101.  
  2102.   end_of_line (str);
  2103.   return;
  2104. }
  2105.  
  2106. static void
  2107. do_fp_ctrl (str, flags)
  2108.      char *str;
  2109.      unsigned long flags;
  2110. {
  2111.   /* FP control registers.
  2112.      Format: <WFS|RFS|WFC|RFC>{cond} Rn  */
  2113.  
  2114.   while (*str == ' ')
  2115.     str++;
  2116.  
  2117.   if (reg_required_here (&str, 12) == FAIL)
  2118.     {
  2119.       if (!inst.error)
  2120.     inst.error = bad_args;
  2121.       return;
  2122.     }
  2123.  
  2124.   end_of_line (str);
  2125.   return;
  2126. }
  2127.  
  2128. static void
  2129. do_fp_ldst (str, flags)
  2130.      char *str;
  2131.      unsigned long flags;
  2132. {
  2133.   while (*str == ' ')
  2134.     str++;
  2135.  
  2136.   switch (inst.suffix)
  2137.     {
  2138.     case SUFF_S:
  2139.       break;
  2140.     case SUFF_D:
  2141.       inst.instruction |= 0x00008000;
  2142.       break;
  2143.     case SUFF_E:
  2144.       inst.instruction |= 0x00400000;
  2145.       break;
  2146.     case SUFF_P:
  2147.       inst.instruction |= 0x00408000;
  2148.       break;
  2149.     default:
  2150.       abort ();
  2151.     }
  2152.  
  2153.   if (fp_reg_required_here (&str, 12) == FAIL)
  2154.     {
  2155.       if (!inst.error)
  2156.     inst.error = bad_args;
  2157.       return;
  2158.     }
  2159.  
  2160.   if (skip_past_comma (&str) == FAIL
  2161.       || cp_address_required_here (&str) == FAIL)
  2162.     {
  2163.       if (!inst.error)
  2164.     inst.error = bad_args;
  2165.       return;
  2166.     }
  2167.  
  2168.   end_of_line (str);
  2169. }
  2170.  
  2171. static void
  2172. do_fp_dyadic (str, flags)
  2173.      char *str;
  2174.      unsigned long flags;
  2175. {
  2176.   while (*str == ' ')
  2177.     str++;
  2178.  
  2179.   switch (inst.suffix)
  2180.     {
  2181.     case SUFF_S:
  2182.       break;
  2183.     case SUFF_D:
  2184.       inst.instruction |= 0x00000080;
  2185.       break;
  2186.     case SUFF_E:
  2187.       inst.instruction |= 0x00080000;
  2188.       break;
  2189.     default:
  2190.       abort ();
  2191.     }
  2192.  
  2193.   if (fp_reg_required_here (&str, 12) == FAIL)
  2194.     {
  2195.       if (! inst.error)
  2196.     inst.error = bad_args;
  2197.       return;
  2198.     }
  2199.  
  2200.   if (skip_past_comma (&str) == FAIL
  2201.       || fp_reg_required_here (&str, 16) == FAIL)
  2202.     {
  2203.       if (! inst.error)
  2204.     inst.error = bad_args;
  2205.       return;
  2206.     }
  2207.  
  2208.   if (skip_past_comma (&str) == FAIL
  2209.       || fp_op2 (&str) == FAIL)
  2210.     {
  2211.       if (! inst.error)
  2212.     inst.error = bad_args;
  2213.       return;
  2214.     }
  2215.  
  2216.   inst.instruction |= flags;
  2217.   end_of_line (str);
  2218.   return;
  2219. }
  2220.  
  2221. static void
  2222. do_fp_monadic (str, flags)
  2223.      char *str;
  2224.      unsigned long flags;
  2225. {
  2226.   while (*str == ' ')
  2227.     str++;
  2228.  
  2229.   switch (inst.suffix)
  2230.     {
  2231.     case SUFF_S:
  2232.       break;
  2233.     case SUFF_D:
  2234.       inst.instruction |= 0x00000080;
  2235.       break;
  2236.     case SUFF_E:
  2237.       inst.instruction |= 0x00080000;
  2238.       break;
  2239.     default:
  2240.       abort ();
  2241.     }
  2242.  
  2243.   if (fp_reg_required_here (&str, 12) == FAIL)
  2244.     {
  2245.       if (! inst.error)
  2246.     inst.error = bad_args;
  2247.       return;
  2248.     }
  2249.  
  2250.   if (skip_past_comma (&str) == FAIL
  2251.       || fp_op2 (&str) == FAIL)
  2252.     {
  2253.       if (! inst.error)
  2254.     inst.error = bad_args;
  2255.       return;
  2256.     }
  2257.  
  2258.   inst.instruction |= flags;
  2259.   end_of_line (str);
  2260.   return;
  2261. }
  2262.  
  2263. static void
  2264. do_fp_cmp (str, flags)
  2265.      char *str;
  2266.      unsigned long flags;
  2267. {
  2268.   while (*str == ' ')
  2269.     str++;
  2270.  
  2271.   if (fp_reg_required_here (&str, 16) == FAIL)
  2272.     {
  2273.       if (! inst.error)
  2274.     inst.error = bad_args;
  2275.       return;
  2276.     }
  2277.  
  2278.   if (skip_past_comma (&str) == FAIL
  2279.       || fp_op2 (&str) == FAIL)
  2280.     {
  2281.       if (! inst.error)
  2282.     inst.error = bad_args;
  2283.       return;
  2284.     }
  2285.  
  2286.   inst.instruction |= flags;
  2287.   end_of_line (str);
  2288.   return;
  2289. }
  2290.  
  2291. static void
  2292. do_fp_from_reg (str, flags)
  2293.      char *str;
  2294.      unsigned long flags;
  2295. {
  2296.   while (*str == ' ')
  2297.     str++;
  2298.  
  2299.   switch (inst.suffix)
  2300.     {
  2301.     case SUFF_S:
  2302.       break;
  2303.     case SUFF_D:
  2304.       inst.instruction |= 0x00000080;
  2305.       break;
  2306.     case SUFF_E:
  2307.       inst.instruction |= 0x00080000;
  2308.       break;
  2309.     default:
  2310.       abort ();
  2311.     }
  2312.  
  2313.   if (fp_reg_required_here (&str, 16) == FAIL)
  2314.     {
  2315.       if (! inst.error)
  2316.     inst.error = bad_args;
  2317.       return;
  2318.     }
  2319.  
  2320.   if (skip_past_comma (&str) == FAIL
  2321.       || reg_required_here (&str, 12) == FAIL)
  2322.     {
  2323.       if (! inst.error)
  2324.     inst.error = bad_args;
  2325.       return;
  2326.     }
  2327.  
  2328.   inst.instruction |= flags;
  2329.   end_of_line (str);
  2330.   return;
  2331. }
  2332.  
  2333. static void
  2334. do_fp_to_reg (str, flags)
  2335.      char *str;
  2336.      unsigned long flags;
  2337. {
  2338.   while (*str == ' ')
  2339.     str++;
  2340.  
  2341.   if (reg_required_here (&str, 12) == FAIL)
  2342.     {
  2343.       if (! inst.error)
  2344.     inst.error = bad_args;
  2345.       return;
  2346.     }
  2347.  
  2348.   if (skip_past_comma (&str) == FAIL
  2349.       || fp_reg_required_here (&str, 0) == FAIL)
  2350.     {
  2351.       if (! inst.error)
  2352.     inst.error = bad_args;
  2353.       return;
  2354.     }
  2355.  
  2356.   inst.instruction |= flags;
  2357.   end_of_line (str);
  2358.   return;
  2359. }
  2360.  
  2361. static void
  2362. insert_reg (entry)
  2363.      int entry;
  2364. {
  2365.   int len = strlen (reg_table[entry].name) + 2;
  2366.   char *buf = (char *) xmalloc (len);
  2367.   char *buf2 = (char *) xmalloc (len);
  2368.   int i = 0;
  2369.  
  2370. #ifdef REGISTER_PREFIX
  2371.   buf[i++] = REGISTER_PREFIX;
  2372. #endif
  2373.  
  2374.   strcpy (buf + i, reg_table[entry].name);
  2375.  
  2376.   for (i = 0; buf[i]; i++)
  2377.     buf2[i] = islower (buf[i]) ? toupper (buf[i]) : buf[i];
  2378.  
  2379.   buf2[i] = '\0';
  2380.  
  2381.   hash_insert (arm_reg_hsh, buf, (PTR) ®_table[entry]);
  2382.   hash_insert (arm_reg_hsh, buf2, (PTR) ®_table[entry]);
  2383. }
  2384.  
  2385. static void
  2386. insert_reg_alias (str, regnum)
  2387.      char *str;
  2388.      int regnum;
  2389. {
  2390.   struct reg_entry *new =
  2391.     (struct reg_entry *)xmalloc (sizeof (struct reg_entry));
  2392.   char *name = xmalloc (strlen (str) + 1);
  2393.   strcpy (name, str);
  2394.  
  2395.   new->name = name;
  2396.   new->number = regnum;
  2397.  
  2398.   hash_insert (arm_reg_hsh, name, (PTR) new);
  2399. }
  2400.  
  2401. static void
  2402. set_constant_flonums ()
  2403. {
  2404.   int i;
  2405.  
  2406.   for (i = 0; i < NUM_FLOAT_VALS; i++)
  2407.     if (atof_ieee ((char *)fp_const[i], 'x', fp_values[i]) == NULL)
  2408.       abort ();
  2409. }
  2410.  
  2411. void
  2412. md_begin ()
  2413. {
  2414.   int i;
  2415.  
  2416.   if ((arm_ops_hsh = hash_new ()) == NULL
  2417.       || (arm_cond_hsh = hash_new ()) == NULL
  2418.       || (arm_flg_hsh = hash_new ()) == NULL
  2419.       || (arm_shift_hsh = hash_new ()) == NULL
  2420.       || (arm_reg_hsh = hash_new ()) == NULL)
  2421.     as_fatal ("Virtual memory exhausted");
  2422.     
  2423.   for (i = 1; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
  2424.     hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
  2425.   for (i = 1; i < sizeof (conds) / sizeof (struct asm_cond); i++)
  2426.     hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
  2427.   for (i = 1; i < sizeof (flags) / sizeof (struct asm_flg); i++)
  2428.     hash_insert (arm_flg_hsh, flags[i].template, (PTR) (flags + i));
  2429.   for (i = 1; i < sizeof (shift) / sizeof (struct asm_shift); i++)
  2430.     hash_insert (arm_shift_hsh, shift[i].template, (PTR) (shift + i));
  2431.  
  2432.   for (i = 0; reg_table[i].name; i++)
  2433.     insert_reg (i);
  2434.  
  2435.   set_constant_flonums ();
  2436. }
  2437.  
  2438. /* This funciton is called once, before the assembler exits.  It is
  2439.    supposed to do any final cleanup for this part of the assembler.
  2440.    */
  2441. void
  2442. md_end ()
  2443. {
  2444. }
  2445.  
  2446. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2447.    for use in the a.out file, and stores them in the array pointed to by buf.
  2448.    This knows about the endian-ness of the target machine and does
  2449.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2450.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2451.    LITTLENUMS (shorts, here at least)
  2452.    */
  2453. void
  2454. md_number_to_chars (buf, val, n)
  2455.      char *buf;
  2456.      valueT val;
  2457.      int n;
  2458. {
  2459.   number_to_chars_littleendian (buf, val, n);
  2460. }
  2461.  
  2462. /*
  2463.    This is identical to the md_atof in m68k.c.  I think this is right,
  2464.    but I'm not sure.
  2465.  
  2466.    Turn a string in input_line_pointer into a floating point constant of type
  2467.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2468.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2469.    */
  2470. char *
  2471. md_atof (type, litP, sizeP)
  2472.      char type;
  2473.      char *litP;
  2474.      int *sizeP;
  2475. {
  2476.   int prec;
  2477.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2478.   LITTLENUM_TYPE *wordP;
  2479.   char *t;
  2480.   char *atof_ieee ();
  2481.  
  2482.   switch (type)
  2483.     {
  2484.  
  2485.     case 'f':
  2486.     case 'F':
  2487.     case 's':
  2488.     case 'S':
  2489.       prec = 2;
  2490.       break;
  2491.  
  2492.     case 'd':
  2493.     case 'D':
  2494.     case 'r':
  2495.     case 'R':
  2496.       prec = 4;
  2497.       break;
  2498.  
  2499.     case 'x':
  2500.     case 'X':
  2501.       prec = 6;
  2502.       break;
  2503.  
  2504.     case 'p':
  2505.     case 'P':
  2506.       prec = 6;
  2507.       break;
  2508.  
  2509.     default:
  2510.       *sizeP = 0;
  2511.       return "Bad call to MD_ATOF()";
  2512.     }
  2513.   t = atof_ieee (input_line_pointer, type, words);
  2514.   if (t)
  2515.     input_line_pointer = t;
  2516.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  2517.   for (wordP = words; prec--;)
  2518.     {
  2519.       md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
  2520.       litP += sizeof (LITTLENUM_TYPE);
  2521.     }
  2522.   return 0;
  2523. }
  2524.  
  2525. /* We have already put the pipeline compensation in the instruction */
  2526.  
  2527. long
  2528. md_pcrel_from (fixP)
  2529.      fixS *fixP;
  2530. {
  2531.   if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section
  2532.       && fixP->fx_subsy == NULL)
  2533.     return 0;    /* HACK */
  2534.  
  2535.   return fixP->fx_where + fixP->fx_frag->fr_address;
  2536. }
  2537.  
  2538. /* Round up a section size to the appropriate boundary. */
  2539. valueT
  2540. md_section_align (segment, size)
  2541.      segT segment;
  2542.      valueT size;
  2543. {
  2544.   /* Round all sects to multiple of 4 */
  2545.   return (size + 3) & ~3;
  2546. }
  2547.  
  2548. /* We have no need to default values of symbols.  */
  2549.  
  2550. /* ARGSUSED */
  2551. symbolS *
  2552. md_undefined_symbol (name)
  2553.      char *name;
  2554. {
  2555.   return 0;
  2556. }
  2557.  
  2558. /* arm_reg_parse () := if it looks like a register, return its token and 
  2559.    advance the pointer. */
  2560.  
  2561. static int
  2562. arm_reg_parse (ccp)
  2563.      register char **ccp;
  2564. {
  2565.   char *start = *ccp;
  2566.   char c;
  2567.   char *p;
  2568.   struct reg_entry *reg;
  2569.  
  2570. #ifdef REGISTER_PREFIX
  2571.   if (*start != REGISTER_PREFIX)
  2572.     return FAIL;
  2573.   p = start + 1;
  2574. #else
  2575.   p = start;
  2576. #ifdef OPTIONAL_REGISTER_PREFIX
  2577.   if (*p == OPTIONAL_REGISTER_PREFIX)
  2578.     p++, start++;
  2579. #endif
  2580. #endif
  2581.   if (!isalpha (*p) || !is_name_beginner (*p))
  2582.     return FAIL;
  2583.  
  2584.   c = *p++;
  2585.   while (isalpha (c) || isdigit (c) || c == '_')
  2586.     c = *p++;
  2587.  
  2588.   *--p = 0;
  2589.   reg = (struct reg_entry *) hash_find (arm_reg_hsh, start);
  2590.   *p = c;
  2591.   
  2592.   if (reg)
  2593.     {
  2594.       *ccp = p;
  2595.       return reg->number;
  2596.     }
  2597.  
  2598.   return FAIL;
  2599. }
  2600.     
  2601. /* Parse an operand that is machine-specific.
  2602.    We just return without modifying the expression if we have nothing
  2603.    to do.  */
  2604.  
  2605. /* ARGSUSED */
  2606. void
  2607. md_operand (expressionP)
  2608.      expressionS *expressionP;
  2609. {
  2610. }
  2611.  
  2612. int
  2613. md_apply_fix (fixP, val)
  2614.      fixS *fixP;
  2615.      valueT *val;
  2616. {
  2617.   offsetT value = *val;
  2618.   int sign;
  2619.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  2620.  
  2621.   assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  2622.  
  2623.   fixP->fx_addnumber = value;    /* Remember value for emit_reloc */
  2624.  
  2625.   /* Note whether this will delete the relocation.  */
  2626.   if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
  2627.     fixP->fx_done = 1;
  2628.  
  2629.   switch (fixP->fx_r_type)
  2630.     {
  2631.     case BFD_RELOC_ARM_IMMEDIATE:
  2632.       value = validate_immediate (value);
  2633.       if (value == -1)
  2634.     {
  2635.       as_bad_where (fixP->fx_file, fixP->fx_line,
  2636.             "invalid constant after fixup\n");
  2637.       break;
  2638.     }
  2639.       buf[0] = value & 0xff;
  2640.       buf[1] = (buf[1] & 0xf0) | ((value >> 8) & 0x0f);
  2641.       break;
  2642.  
  2643.     case BFD_RELOC_ARM_OFFSET_IMM:
  2644.       sign = value >= 0;
  2645.       value = validate_offset_imm (value);
  2646.       if (value < 0)
  2647.     value = -value;
  2648.       buf[0] = value & 0xff;
  2649.       buf[1] = (buf[1] & 0xf0) | ((value >> 8) & 0x0f);
  2650.       buf[2] |= sign ? 0x80 : 0;
  2651.       break;
  2652.  
  2653.     case BFD_RELOC_ARM_SHIFT_IMM:
  2654.       if (value < 0 || value > 32
  2655.       || (value == 32 
  2656.           && (((*buf & 0x60) == 0) || (*buf & 0x60) == 0x60)))
  2657.     {
  2658.       as_bad_where (fixP->fx_file, fixP->fx_line,
  2659.             "shift expression is too large");
  2660.       break;
  2661.     }
  2662.  
  2663.       if (value == 32)
  2664.     {
  2665.       *buf &= ~0x60;
  2666.       break;
  2667.     }
  2668.       buf[0] |= value & 0x01 << 7;
  2669.       buf[1] |= (value >> 1) & 0x0f;
  2670.       break;
  2671.  
  2672.     case BFD_RELOC_ARM_SWI:
  2673.       if (value < 0 || value > 0x00ffffff)
  2674.     as_bad_where (fixP->fx_file, fixP->fx_line, "Invalid swi expression");
  2675.       buf[0] = value;
  2676.       buf[1] = value >> 8;
  2677.       buf[2] = value >> 16;
  2678.       break;
  2679.  
  2680.     case BFD_RELOC_ARM_MULTI:
  2681.       if (value < 0 || value > 0xffff)
  2682.     as_bad_where (fixP->fx_file, fixP->fx_line,
  2683.               "Invalid expression in load/store multiple");
  2684.       buf[0] |= value;
  2685.       buf[1] |= value >> 8;
  2686.       break;
  2687.  
  2688.     case BFD_RELOC_ARM_PCREL_BRANCH:
  2689.       value = (value >> 2) & 0x00ffffff;
  2690.       value += ((unsigned int)(buf[0]) | ((unsigned int)(buf[1]) << 8) 
  2691.         | ((unsigned int)(buf[2]) << 16));
  2692.       buf[0] = value;
  2693.       buf[1] = value >> 8;
  2694.       buf[2] = value >> 16;
  2695.       break;
  2696.  
  2697.     case BFD_RELOC_8:
  2698.       if (fixP->fx_done || fixP->fx_pcrel)
  2699.     md_number_to_chars (buf, value, 1);
  2700.       break;
  2701.  
  2702.     case BFD_RELOC_16:
  2703.       if (fixP->fx_done || fixP->fx_pcrel)
  2704.     md_number_to_chars (buf, value, 2);
  2705.       break;
  2706.  
  2707.     case BFD_RELOC_32:
  2708.       if (fixP->fx_done || fixP->fx_pcrel)
  2709.     md_number_to_chars (buf, value, 4);
  2710.       break;
  2711.  
  2712.     case BFD_RELOC_ARM_CP_OFF_IMM:
  2713.       sign = value >= 0;
  2714.       if (value < -1023 || value > 1023 || (value & 3))
  2715.     as_bad_where (fixP->fx_file, fixP->fx_line,
  2716.               "Illegal value for co-processor offset");
  2717.       if (value < 0)
  2718.     value = -value;
  2719.       buf[0] = value >> 2;
  2720.       if (sign)
  2721.     buf[2] |= 0x80;
  2722.       break;
  2723.  
  2724.     case BFD_RELOC_NONE:
  2725.     default:
  2726.       as_bad_where (fixP->fx_file, fixP->fx_line,
  2727.             "Bad relocation fixup type (%d)\n", fixP->fx_r_type);
  2728.     }
  2729.  
  2730.   return 1;
  2731. }
  2732.  
  2733. /* Translate internal representation of relocation info to BFD target
  2734.    format.  */
  2735. arelent *
  2736. tc_gen_reloc (section, fixp)
  2737.      asection *section;
  2738.      fixS *fixp;
  2739. {
  2740.   arelent *reloc;
  2741.   bfd_reloc_code_real_type code;
  2742.  
  2743.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  2744.   assert (reloc != 0);
  2745.  
  2746.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2747.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2748.  
  2749.   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
  2750.   if (fixp->fx_pcrel == 0)
  2751.     reloc->addend = fixp->fx_offset;
  2752.   else
  2753.     reloc->addend = fixp->fx_offset = reloc->address;
  2754.  
  2755.   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
  2756.   if (fixp->fx_pcrel == 0)
  2757.     reloc->addend = fixp->fx_offset;
  2758.   else
  2759.     reloc->addend = fixp->fx_offset = reloc->address;
  2760.  
  2761.   switch (fixp->fx_r_type)
  2762.     {
  2763.     case BFD_RELOC_8:
  2764.       if (fixp->fx_pcrel)
  2765.     {
  2766.       code = BFD_RELOC_8_PCREL;
  2767.       break;
  2768.     }
  2769.     case BFD_RELOC_16:
  2770.       if (fixp->fx_pcrel)
  2771.     {
  2772.       code = BFD_RELOC_16_PCREL;
  2773.       break;
  2774.     }
  2775.     case BFD_RELOC_32:
  2776.       if (fixp->fx_pcrel)
  2777.     {
  2778.       code = BFD_RELOC_32_PCREL;
  2779.       break;
  2780.     }
  2781.     case BFD_RELOC_ARM_PCREL_BRANCH:
  2782.       code = fixp->fx_r_type;
  2783.       break;
  2784.     case BFD_RELOC_ARM_IMMEDIATE:
  2785.     case BFD_RELOC_ARM_OFFSET_IMM:
  2786.     case BFD_RELOC_ARM_SHIFT_IMM:
  2787.     case BFD_RELOC_ARM_SWI:
  2788.     case BFD_RELOC_ARM_MULTI:
  2789.     case BFD_RELOC_ARM_CP_OFF_IMM:
  2790.       as_bad ("Internal_relocation (type %d) not fixed up\n", fixp->fx_r_type);
  2791.       return NULL;
  2792.     default:
  2793.       abort ();
  2794.     }
  2795.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  2796.   assert (reloc->howto != 0);
  2797.  
  2798.   return reloc;
  2799. }
  2800.  
  2801. CONST int md_short_jump_size = 4;
  2802. CONST int md_long_jump_size = 4;
  2803.  
  2804. /* These should never be called on the arm */
  2805. void
  2806. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2807.      char *ptr;
  2808.      addressT from_addr, to_addr;
  2809.      fragS *frag;
  2810.      symbolS *to_symbol;
  2811. {
  2812.   as_fatal ("md_create_long_jump\n");
  2813. }
  2814.  
  2815. void
  2816. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2817.      char *ptr;
  2818.      addressT from_addr, to_addr;
  2819.      fragS *frag;
  2820.      symbolS *to_symbol;
  2821. {
  2822.   as_fatal ("md_create_short_jump\n");
  2823. }
  2824.  
  2825. int
  2826. md_estimate_size_before_relax (fragP, segtype)
  2827.      fragS *fragP;
  2828.      segT segtype;
  2829. {
  2830.   as_fatal ("md_estimate_size_before_relax\n");
  2831.   return (1);
  2832. }
  2833.  
  2834. void
  2835. output_inst (str)
  2836.      char *str;
  2837. {
  2838.   char *to = NULL;
  2839.     
  2840.   if (inst.error)
  2841.     {
  2842.       as_bad ("%s -- statement `%s'\n", inst.error, str);
  2843.       return;
  2844.     }
  2845.  
  2846.   to = frag_more (INSN_SIZE);
  2847.   md_number_to_chars (to, inst.instruction, 4);
  2848.  
  2849.   if (inst.reloc.type != BFD_RELOC_NONE)
  2850.     fix_new_arm (frag_now, to - frag_now->fr_literal,
  2851.          4, &inst.reloc.exp, inst.reloc.pc_rel,
  2852.          inst.reloc.type);
  2853.  
  2854.   return;
  2855. }
  2856.  
  2857. void
  2858. md_assemble (str)
  2859.      char *str;
  2860. {
  2861.   char c;
  2862.   CONST struct asm_opcode *opcode;
  2863.   char *p, *q, *start;
  2864.  
  2865.   memset (&inst, '\0', sizeof (inst));
  2866.   inst.reloc.type = BFD_RELOC_NONE;
  2867.  
  2868.   if (*str == ' ')
  2869.     str++;            /* Skip leading white space */
  2870.     
  2871.   /* scan up to the end of the op-code, which must end in white space or
  2872.      end of string */
  2873.   for (start = p = str; *p != '\0'; p++)
  2874.     if (*p == ' ')
  2875.       break;
  2876.     
  2877.   if (p == str)
  2878.     {
  2879.       as_bad ("No operator -- statement `%s'\n", str);
  2880.       return;
  2881.     }
  2882.  
  2883.   /* p now points to the end of the opcode, probably white space, but we have
  2884.      to break the opcode up in case it contains condionals and flags;
  2885.      keep trying with progressively smaller basic instructions until one
  2886.      matches, or we run out of opcode. */
  2887.   q = (p - str > LONGEST_INST) ? str + LONGEST_INST : p;
  2888.   for (; q != str; q--)
  2889.     {
  2890.       c = *q;
  2891.       *q = '\0';
  2892.       opcode = (CONST struct asm_opcode *) hash_find (arm_ops_hsh, str);
  2893.       *q = c;
  2894.       if (opcode && opcode->template)
  2895.     {
  2896.       unsigned long valid_flags = 0xffffffff;
  2897.       unsigned long flag_bits = 0;
  2898.       char *r;
  2899.         
  2900.       inst.instruction = opcode->value;
  2901.       if (q == p)        /* Just a simple opcode */
  2902.         {
  2903.           if (opcode->comp_suffix != 0)
  2904.         as_bad ("Opcode `%s' must have suffix from <%s>\n", str,
  2905.             opcode->comp_suffix);
  2906.           else
  2907.         {
  2908.           inst.instruction |= COND_ALWAYS;
  2909.           (*opcode->parms)(q, 0);
  2910.         }
  2911.           output_inst (start);
  2912.           return;
  2913.         }
  2914.  
  2915.       /* Now check for a conditional */
  2916.       r = q;
  2917.       if (p - r >= 2)
  2918.         {
  2919.           CONST struct asm_cond *cond;
  2920.           char d = *(r + 2);
  2921.           
  2922.           *(r + 2) = '\0';
  2923.           cond = (CONST struct asm_cond *) hash_find (arm_cond_hsh, r);
  2924.           *(r + 2) = d;
  2925.           if (cond)
  2926.         {
  2927.           if (cond->value == 0xf0000000)
  2928.             as_tsktsk 
  2929.               ("Warning: Use of the 'nv' conditional is deprecated\n");
  2930.           inst.instruction |= cond->value;
  2931.           r += 2;
  2932.         }
  2933.           else
  2934.         inst.instruction |= COND_ALWAYS;
  2935.         }
  2936.       else
  2937.         inst.instruction |= COND_ALWAYS;
  2938.  
  2939.       /* if there is a compulsory suffix, it should come here, before
  2940.          any optional flags. */
  2941.       if (opcode->comp_suffix)
  2942.         {
  2943.           CONST char *s = opcode->comp_suffix;
  2944.  
  2945.           while (*s)
  2946.         {
  2947.           inst.suffix++;
  2948.           if (*r == *s)
  2949.             break;
  2950.           s++;
  2951.         }
  2952.           
  2953.           if (*s == '\0')
  2954.         {
  2955.           as_bad ("Opcode `%s' must have suffix from <%s>\n", str,
  2956.               opcode->comp_suffix);
  2957.           return;
  2958.         }
  2959.         
  2960.           r++;
  2961.         }
  2962.  
  2963.       /* The remainder, if any should now be flags for the instruction;
  2964.          Scan these checking each one found with the opcode and any
  2965.          flags previously found */
  2966.       while (r != p)
  2967.         {
  2968.           char d;
  2969.           char *s;
  2970.           
  2971.           s = (p - r > LONGEST_FLAG) ? r + LONGEST_FLAG : p;
  2972.           for (; s != r; s--)
  2973.         {
  2974.           CONST struct asm_flg *flag;
  2975.             
  2976.           d = *s;
  2977.           *s = '\0';
  2978.           flag = (CONST struct asm_flg *)hash_find (arm_flg_hsh, r);
  2979.  
  2980.           *s = d;
  2981.           if (flag 
  2982.               && (valid_flags & (1 << (flag - flags)))
  2983.               && opcode->flags[(flag - flags) - 1])
  2984.             {
  2985.               flag_bits |= opcode->flags[(flag - flags) - 1];
  2986.               r = s;
  2987.               valid_flags &= flag->more_flags;
  2988.               break;
  2989.             }
  2990.         }
  2991.  
  2992.           if (!flag_bits)
  2993.         goto try_shorter;
  2994.         }
  2995.  
  2996.       (*opcode->parms) (p, flag_bits);
  2997.       output_inst (start);
  2998.       return;
  2999.     }
  3000.  
  3001.     try_shorter:
  3002.     ;
  3003.     }
  3004.   /* It wasn't an instruction, but it might be a register alias of the form
  3005.      alias .req reg
  3006.      */
  3007.   q = p;
  3008.   while (*q == ' ')
  3009.     q++;
  3010.  
  3011.   c = *p;
  3012.   *p = '\0';
  3013.     
  3014.   if (*q && arm_reg_parse (&str) == FAIL && !strncmp (q, ".req ", 4))
  3015.     {
  3016.       char *r;
  3017.       
  3018.       q += 4;
  3019.       while (*q == ' ')
  3020.     q++;
  3021.  
  3022.       for (r = q; *r != '\0'; r++)
  3023.     if (*r == ' ')
  3024.       break;
  3025.  
  3026.       if (r != q)
  3027.     {
  3028.       int regnum;
  3029.       char d = *r;
  3030.  
  3031.       *r = '\0';
  3032.       regnum = arm_reg_parse (&q);
  3033.       *r = d;
  3034.       if (regnum != FAIL)
  3035.         {
  3036.           insert_reg_alias (str, regnum);
  3037.           *p = c;
  3038.           return;
  3039.         }
  3040.     }
  3041.     }
  3042.   *p = c;
  3043.   as_bad ("bad instruction `%s'", start);
  3044. }
  3045.  
  3046. /*
  3047.  * md_parse_option
  3048.  *      Invocation line includes a switch not recognized by the base assembler.
  3049.  *      See if it's a processor-specific option.  These are:
  3050.  *
  3051.  */
  3052.  
  3053. int
  3054. md_parse_option (c, arg)
  3055.      int c;
  3056.      char *arg;
  3057. {
  3058.   return 0;
  3059. }
  3060.  
  3061. void
  3062. md_show_usage (fp)
  3063.      FILE *fp;
  3064. {
  3065. }
  3066.  
  3067. /* We need to be able to fix up arbitrary expressions in some statements.
  3068.    This is so that we can handle symbols that are an arbitrary distance from
  3069.    the pc.  The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
  3070.    which returns part of an address in a form which will be valid for
  3071.    a data instruction.  We do this by pushing the expression into a symbol
  3072.    in the expr_section, and creating a fix for that.  */
  3073.  
  3074. static void
  3075. fix_new_arm (frag, where, size, exp, pc_rel, reloc)
  3076.      fragS *frag;
  3077.      int where;
  3078.      short int size;
  3079.      expressionS *exp;
  3080.      int pc_rel;
  3081.      int reloc;
  3082. {
  3083.   fixS *new_fix;
  3084.  
  3085.   switch (exp->X_op)
  3086.     {
  3087.     case O_constant:
  3088.     case O_symbol:
  3089.     case O_add:
  3090.     case O_subtract:
  3091.       new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
  3092.       break;
  3093.  
  3094.     default:
  3095.       {
  3096.     const char *fake;
  3097.     symbolS *symbolP;
  3098.     
  3099.     /* FIXME: This should be something which decode_local_label_name
  3100.        will handle.  */
  3101.     fake = FAKE_LABEL_NAME;
  3102.  
  3103.     /* Putting constant symbols in absolute_section rather than
  3104.        expr_section is convenient for the old a.out code, for which
  3105.        S_GET_SEGMENT does not always retrieve the value put in by
  3106.        S_SET_SEGMENT.  */
  3107.     symbolP = symbol_new (fake, expr_section, 0, &zero_address_frag);
  3108.     symbolP->sy_value = *exp;
  3109.     new_fix = fix_new (frag, where, size, symbolP, 0, pc_rel, reloc);
  3110.       }
  3111.       break;
  3112.     }
  3113.  
  3114.   return;
  3115. }
  3116.